﻿<script type="text/javascript">
    
    function init() 
    {        
        jQuery.getScript("/js/jquery-ui-1.8.11.custom.min.js", ResetColors);
    }

    function ResetColors() 
    {
        jQuery('#divCaptcha').load('/_layouts/SolidQ.MSS.Controls/Captcha/SolidQCaptchaBuilder.aspx?' + Math.random() + '&language=@Language@' + ' #SolidQCaptcha-Container', SetDragAndDrop).fadeIn("slow");
        jQuery('input[name$=@InputHiddenID@]').val('');
    }

    function VisualValidation(id, currentDiv) 
    {
        jQuery.ajax({
            type: "GET",
            url: "/_layouts/SolidQ.MSS.Controls/Captcha/SolidQCaptchaW.aspx?wqs=" + id,
            dataType: "xml",
            success: function (data) {

                if (jQuery(data).text() == 'False') {
                    //Mostramos un texto de error dependiente del idioma
                    //English
                    if (jQuery('.SolidQCaptcha-TextZone').text().indexOf('square') != -1) {
                        jQuery('.SolidQCaptcha-TextZone').text('Wrong color. Try again!').removeClass('SolidQCaptcha-TextZone').addClass('SolidQCaptcha-WrongColour');
                    }
                    else 
                    {	//Spanish
                        if (jQuery('.SolidQCaptcha-TextZone').text().indexOf('cuadrado') != -1) {
                            jQuery('.SolidQCaptcha-TextZone').text('Color incorrecto. Pruebe de nuevo!');
                        }
                    }

                    jQuery('#SolidQCaptcha-BlankZone').hide().css('background', "transparent url('/_layouts/Images/SolidQ.MSS.Controls/Captcha/falsemark.png')").fadeIn('fast');
                }
                else {
                    jQuery('#SolidQCaptcha-BlankZone').hide().css('background', "transparent url('/_layouts/Images/SolidQ.MSS.Controls/Captcha/truemark.png')").fadeIn('fast');
                    jQuery('input[name$=@InputHiddenID@]').val(jQuery(currentDiv).attr('Id').replace('SolidQCaptcha-Draggable-', ''));
                }
            }
        });
    }


    function SetDragAndDrop() 
    {
        jQuery('.SolidQCaptcha-ColourX').hide().draggable({ helper: 'clone', revert: 'invalid', opacity: 0.55 }).fadeIn("slow");
        jQuery('.SolidQCaptcha-BlankZone').droppable({ accept: '.SolidQCaptcha-ColourX', tolerance: 'intersect' });

        //On drop of draggable object
        jQuery('.SolidQCaptcha-BlankZone').bind('drop', function (event, ui) {

            //Obtaining the circle file
            var circle = jQuery(ui.draggable).css('background-image');
            circle = circle.substring(circle.indexOf('squares/'), circle.indexOf('.jpg'));
            circle = circle.replace('squares/', '');

            jQuery('#SolidQCaptcha-BlankZone').css('background', "transparent url('/_layouts/Images/SolidQ.MSS.Controls/Captcha/circles/" + circle + circle + ".png')").fadeIn('slow');
            jQuery('.SolidQCaptcha-ColourX').draggable('disable');

            //Checking validation
            setTimeout(function () { VisualValidation(jQuery(ui.draggable).attr('Id').replace('SolidQCaptcha-Draggable-', ''), jQuery(ui.draggable)); }, 500);
        });
    }

    jQuery(document).ready(init);

</script>

<div id="divCaptcha" class="divCaptcha"><!-- --></div>